package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.utils.IdUtils;
import com.lw.sbdemo2.common.utils.ValidUtil;
import com.lw.sbdemo2.common.web.anno.Required;
import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.entity.TkTermProduct;
import com.lw.sbdemo2.service.TkTermProductService;
import com.lw.sbdemo2.common.web.anno.ResultController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>标题: 试卷商品主表服务 - 请求控制层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-5-20
 */
@ResultController
@Api(description = "TkTermProductController", tags = {"试卷商品主表服务"})
@RequestMapping(value = "/tkTermProduct")
public class TkTermProductController extends BaseController {

    /**
     * 试卷商品主表服务
     */
    @Autowired
    private TkTermProductService tkTermProductService;
	
	@ApiOperation(value = "获取试卷商品主表列表")
    @GetMapping("")
    public List<TkTermProduct> findList(TkTermProduct tkTermProduct) {
        return tkTermProductService.findList(tkTermProduct);
    }

    @ApiOperation(value = "获取试卷商品主表列表（分页）", response = PageInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/page")
    public PageInfo<TkTermProduct> page(String query, @Required("pageNum") PageInfo pageInfo, TkTermProduct tkTermProduct) {
        return tkTermProductService.findListPage(query, pageInfo, tkTermProduct);
    }

    @ApiOperation(value = "获取试卷商品主表详细信息", notes = "根据url的id来获取试卷商品主表详细信息")
    @ApiImplicitParam(name = "id", value = "试卷商品主表ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public TkTermProduct get(@PathVariable String id) {
        return tkTermProductService.getById(id);
    }

    @ApiOperation(value = "创建试卷商品主表")
    @PostMapping("/insert")
    public void insert(TkTermProduct tkTermProduct) {
		tkTermProduct.setCreatedTime(new Date());
        tkTermProduct.setTermId(IdUtils.uuid());
        tkTermProductService.insert(tkTermProduct);
    }

    @ApiOperation(value = "更新试卷商品主表详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "试卷商品主表ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/update")
    public void update(TkTermProduct tkTermProduct) {
		tkTermProduct.setModifiedTime(new Date());
        tkTermProductService.update(tkTermProduct);
    }

    @ApiOperation(value = "删除试卷商品主表", notes = "删除试卷商品主表")
    @ApiImplicitParam(name = "id", value = "试卷商品主表ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/delete")
    public void deleteTkTermProduct(TkTermProduct tkTermProduct) {
        tkTermProductService.delete(tkTermProduct);
    }
    
}